package com.ruoyi.system.service.impl;

import java.math.BigDecimal;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.ConsumeDataVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TRefusalRecordsMapper;
import com.ruoyi.system.domain.TRefusalRecords;
import com.ruoyi.system.service.ITRefusalRecordsService;

/**
 * 拒付Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@Service
public class TRefusalRecordsServiceImpl implements ITRefusalRecordsService 
{
    @Autowired
    private TRefusalRecordsMapper tRefusalRecordsMapper;

    /**
     * 查询拒付
     * 
     * @param id 拒付主键
     * @return 拒付
     */
    @Override
    public TRefusalRecords selectTRefusalRecordsById(Long id)
    {
        return tRefusalRecordsMapper.selectTRefusalRecordsById(id);
    }

    /**
     * 查询拒付列表
     * 
     * @param tRefusalRecords 拒付
     * @return 拒付
     */
    @Override
    public List<TRefusalRecords> selectTRefusalRecordsList(TRefusalRecords tRefusalRecords)
    {
        return tRefusalRecordsMapper.selectTRefusalRecordsList(tRefusalRecords);
    }

    /**
     * 新增拒付
     * 
     * @param tRefusalRecords 拒付
     * @return 结果
     */
    @Override
    public int insertTRefusalRecords(TRefusalRecords tRefusalRecords)
    {
        if (tRefusalRecords.getRefuseAmount() != null){
            tRefusalRecords.setCamExam(tRefusalRecords.getRefuseAmount().multiply(BigDecimal.valueOf(0.9)));
            tRefusalRecords.setPerExam(tRefusalRecords.getRefuseAmount().multiply(BigDecimal.valueOf(0.1)));
        }
        tRefusalRecords.setCreateTime(DateUtils.getNowDate());
        return tRefusalRecordsMapper.insertTRefusalRecords(tRefusalRecords);
    }

    /**
     * 修改拒付
     * 
     * @param tRefusalRecords 拒付
     * @return 结果
     */
    @Override
    public int updateTRefusalRecords(TRefusalRecords tRefusalRecords)
    {
        if (tRefusalRecords.getRefuseAmount() != null){
            tRefusalRecords.setCamExam(tRefusalRecords.getRefuseAmount().multiply(BigDecimal.valueOf(0.9)));
            tRefusalRecords.setPerExam(tRefusalRecords.getRefuseAmount().multiply(BigDecimal.valueOf(0.1)));
        }
        return tRefusalRecordsMapper.updateTRefusalRecords(tRefusalRecords);
    }

    /**
     * 批量删除拒付
     * 
     * @param ids 需要删除的拒付主键
     * @return 结果
     */
    @Override
    public int deleteTRefusalRecordsByIds(Long[] ids)
    {
        return tRefusalRecordsMapper.deleteTRefusalRecordsByIds(ids);
    }

    /**
     * 删除拒付信息
     * 
     * @param id 拒付主键
     * @return 结果
     */
    @Override
    public int deleteTRefusalRecordsById(Long id)
    {
        return tRefusalRecordsMapper.deleteTRefusalRecordsById(id);
    }

    @Override
    public void syn() {
        List<TRefusalRecords> list = tRefusalRecordsMapper.selectTRefusalRecordsList(new TRefusalRecords());
        if (!list.isEmpty()){
            for (TRefusalRecords tRefusalRecords : list) {
                if (tRefusalRecords.getRefuseAmount() != null){
                    tRefusalRecords.setCamExam(tRefusalRecords.getRefuseAmount().multiply(BigDecimal.valueOf(0.9)));
                    tRefusalRecords.setPerExam(tRefusalRecords.getRefuseAmount().multiply(BigDecimal.valueOf(0.1)));
                    tRefusalRecordsMapper.updateTRefusalRecords(tRefusalRecords);
                }
            }
        }
    }

    @Override
    public ConsumeDataVo allSummary(TRefusalRecords tRefusalRecords) {
        ConsumeDataVo consumeDataVo = new ConsumeDataVo();
        consumeDataVo.setAllConsume(tRefusalRecordsMapper.amountByAll(tRefusalRecords));
        consumeDataVo.setAllCamExam(tRefusalRecordsMapper.amountByCamExam(tRefusalRecords));
        consumeDataVo.setAllPerExam(tRefusalRecordsMapper.amountByPerExam(tRefusalRecords));
        return consumeDataVo;
    }

    @Override
    public ConsumeDataVo mySummary(TRefusalRecords tRefusalRecords) {
        ConsumeDataVo consumeDataVo = new ConsumeDataVo();
        consumeDataVo.setAllConsume(tRefusalRecordsMapper.amountByAll(tRefusalRecords));
        consumeDataVo.setAllCamExam(tRefusalRecordsMapper.amountByCamExam(tRefusalRecords));
        consumeDataVo.setAllPerExam(tRefusalRecordsMapper.amountByPerExam(tRefusalRecords));
        return consumeDataVo;
    }
}
